home *** CD-ROM | disk | FTP | other *** search
- /* GrabSlotDrivers.c
- Repeatedly calls the Slot Manager to get every slot driver and puts each in its
- own file. These files can then be perused with the ResEdit CODE viewer.
-
- The ResEdit CODE viewer is a public domain file, for use with ResEdit, distributed by:
- Ira L. Ruben
- Apple Computer, Inc.
- 20525 Mariani Ave., MS: 37-A
- Cupertino, Ca. 95014
- Ira@Apple.Com
- ftp://ftp.apple.com/dts/mac/tools/resedit/
-
- Note that GrabSlotDrivers gets the driver directly from the card's configuration
- ROM, whereas it is possible that your run-time System is actually superceding
- that by a later version of the driver loaded from the System file or by an INIT.
- If you want the active version of the driver it would be best to get it from the
- device manager, which is what GrabVideoDrivers.c does, though it skips non-video
- devices.
-
- HISTORY:
- 2/89 dgp Wrote it as "video hacker II" using THINK C 3.
- 1/3/93 dgp updated it to THINK C 5 and renamed it GrabSlotDrivers.c
- 5/11/93 dgp added check for Slot Manager, in response to bug report by Jonathan Brecher.
- 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
- Metrowerks CodeWarrior C.
- 9/5/94 dgp removed assumption in printf's that int==short.
- 6/8/95 dgp Made sure that Mac structs are always 68k aligned.
- */
- #include "VideoToolbox.h"
- //#include <Errors.h>
- //#include <Resources.h>
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
- #include <ROMDefs.h>
- //#include <Video.h>
-
- #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
- #pragma options align=mac68k
- #endif
-
- typedef struct {
- short flags;
- short blanks[3];
- short open;
- short prime;
- short control;
- short status;
- short close;
- Str255 name;
- } VideoDriver;
-
- #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
- #pragma options align=reset
- #endif
-
- void AddResourceToFile(unsigned char *filename,unsigned char *name,ResType type,int id
- ,Handle handle);
- void GrabSlotDrivers(void);
-
- void main(void)
- {
- Require(0);
- if(!TrapAvailable(_SlotManager))
- PrintfExit("Sorry, no Slot Manager.\n");
- MaximizeConsoleHeight();
- printf(BreakLines("Welcome to GrabSlotDrivers.\n"
- "This programs copies all drivers from your slot devices. "
- "Note that this gets the driver from the card's configuration ROM, whereas "
- "it is possible that at run-time your System replaces "
- "that by a later version of the driver loaded from the System file or INIT.\n\n",78));
- GrabSlotDrivers();
- }
-
- void GrabSlotDrivers(void)
- {
- SpBlock spBlock;
- SEBlock sEBlock;
- unsigned char name[256],filename[32];
- int error,version;
- Ptr *handle;
- VideoDriver *videoDriverPtr;
- unsigned char *bytePtr;
- Boolean newSlotMgr; // SGetTypeSRsrc requires system 7 slot manager
-
- newSlotMgr=(SVersion(&spBlock)==noErr);
- spBlock.spsExecPBlk = (Ptr) &sEBlock;
- spBlock.spSlot = 0;
- spBlock.spID = 0;
- spBlock.spExtDev = 0;
- /*
- spBlock.spCategory=catDisplay;
- spBlock.spCType=0;
- spBlock.spDrvrSW=0;
- spBlock.spDrvrHW=0;
- spBlock.spTBMask=3; // ignore DrvrHW and DrvrSW
- */
- while(1){
- spBlock.spParamData=5; // next resource, whether enabled & disabled
- if(newSlotMgr)error=SGetSRsrc(&spBlock);
- else error=SNextSRsrc(&spBlock);
- if(error==smNoMoresRsrcs) break;
- if(error){
- printf("SNextSRsrc/SGetSRsrc error %d\n",error);
- break;
- }
- spBlock.spResult = (unsigned long) &name;
- error = SReadDrvrName(&spBlock);
- p2cstr(name);
- printf("SReadDrvrName=%s\n",name);
- c2pstr((char *)name);
- printf("spSlot=%d,spID=%u,spExtDev=%d"
- ,(int)spBlock.spSlot,(unsigned int)spBlock.spID,(int)spBlock.spExtDev);
- printf(",spCategory=%d,spCType=%d,spDrvrSW=%d,spDrvrHW=%d,spRefNum=%d\n"
- ,(int)spBlock.spCategory,(int)spBlock.spCType,(int)spBlock.spDrvrSW
- ,(int)spBlock.spDrvrHW,(int)spBlock.spRefNum);
- memcpy(filename,name,32);
- /* filename must be truncated to 31 characters */
- if(filename[0] > 31) filename[0]=31;
- // Replace leading "." by "-" since the Mac filing system
- // is confused by filenames beginning with ".".
- if(filename[1]=='.')filename[1]='-';
-
- /* get handle to desired driver resource */
- error = SGetDriver(&spBlock);
- if(!error) {
- handle = (Ptr *) spBlock.spResult;
-
- // Is this a video driver?
- videoDriverPtr=*(VideoDriver **)handle;
- if(EqualString(name,videoDriverPtr->name,1,1)){
- // Probably is a video driver. The version number of a video driver
- // is the first word-aligned word after the name string.
- bytePtr= videoDriverPtr->name;
- bytePtr += 1+bytePtr[0]; /* go to end of Pascal string */
- bytePtr = (unsigned char *)((long)(bytePtr+1) & ~1); // round up to word boundary
- version = *(short *)bytePtr;
- } else version=rand();
-
- AddResourceToFile(filename,name,'DRVR',version,handle);
- printf("Driver copied to file “%s”, with resource id %d\n"
- ,p2cstr(filename),(int)version);
- DisposHandle(handle);
- }
- else printf("No driver.\n");
- printf("\n");
- }
- }
-
-